<?php
namespace Utuo\TagLib;

use Think\Template\TagLib;

class House extends TagLib {
	
	/**
	 * 定义标签列表
	 * @var array
	 */
	protected $tags = array(
		'list' => array('attr' => 'id,paginate,pagesize', 'close' => 1), //获取指定分类列表
		'page' => array('attr'=>'', 'close'=>0),
		'detail' => array('attr'=>'id,houseid', 'close'=>1),
			'typelist'
			,'scenelist',
			'type',
			'scene',
			'house'
	);
	
	/**
	 * 文章列表
	 * @param array $tags
	 * @param string $content
	 */
	public function _list($tag, $content) {
		$p = I("p", 1, "intval");
		$id = $tag['id'];
		$table_tag = 'house';
		$pagesize   = $tag['pagesize']?$tag['pagesize']:10;
		$paginate   = $tag['paginate']?'1':'0';
		$tt = <<<'EOT'
		<?php
			$list = D('House')->content_list($sid, {0}, {1}, {2});
			if({0}){
				$page = new \Think\Page($list['count'], {1}, $parameter = null);
				$pagination = $page->show();
			}
			$__LIST__ = $list['data'];
			foreach ($__LIST__ as &$v){
				$v['url'] = get_content_url({3}, $sid, null, $v['id']);
			}
		?>
		<volist name="__LIST__" id="{4}">
		{5}
		</volist>				
EOT;
		$parse = \Utuo\String::format($tt, $paginate, $pagesize, $p, $table_tag, $id, $content);
		return $parse;
	}	
	
	public function _page($tag, $content){
		return <<<'EOT'
		<?php
			echo $pagination;
		?>
EOT;
	}
	
	/**
	 * 内容详细
	 * @param unknown $tag
	 * @param unknown $content
	 * @return string
	 */
	public function _detail($tag, $content) {
		$id = $tag['id'];
		$houseid  = $tag['houseid'];
		if(!$houseid) $houseid = I('arc', 0, 'intval');
		$tt = <<<'EOT'
		<?php
			$__CONTENT__ = array();
			$houseid = {0};
			if($content && ($content['id']==$houseid)) {
				$__CONTENT__[] = $content;
			}elseif($houseid) {
				$list = D('House')->content_detail($houseid, $sid);
				$list['data'] && $__CONTENT__[] = $list['data'];
			}
		?>
		<volist name="__CONTENT__" id="{1}">
		{2}
		</volist>
EOT;
		$parse = \Utuo\String::format($tt, $houseid, $id, $content);
		return $parse;
	}
}